<?php
function EntryContentShort($target, $mother){
	global $service, $configVal, $database, $blogid, $suri, $category, $defaultURL, $blog, $entries;
	requireComponent('Textcube.Function.misc');
	$data = misc::fetchConfigVal($configVal);

	if (!isset($blog['blogLanguage'])) {
		$blog['blogLanguage'] = $service['language'];
	}
	switch($blog['blogLanguage']) {
		case "zh-TW":
			$moretext = "[繼續閱讀]";
		break;
		case "zh-CN":
			$moretext = "[继续阅读]";
		break;
		default:
			$moretext = "[더보기]";
	}
	if(is_null($data)){
		$data['maxLength']	= 360;
		$data['htmlcheck']	= 1;
		$data['moretext']	= $moretext;
		$data['textcolor']	= "#48789B";
		$data['textsize']	= 11;
	}

	$data['maxLength']	= ($data['maxLength'])?$data['maxLength']:360;
	$data['htmlcheck']	= ($data['htmlcheck'])?$data['htmlcheck']:1;
	$data['moretext']	= ($data['moretext'])?$data['moretext']:$moretext;
	$data['textcolor']	= ($data['textcolor'])?$data['textcolor']:"#48789B";
	$data['textsize']	= ($data['textsize'])?$data['textsize']:11;
	
	if($data['htmlcheck']==1){
		$content = preg_replace('/<(script|style)[^>]*>.*?<\/\1>/si','', $target);
		$content = strip_tags(str_replace(array('&nbsp;','\r\n'),array('',''), $content));
	}else{
		$content = $target;
	}

	if(strlen($content) > $data['maxLength']){
		$slogan		= ($blog['useSlogan'])?DBQuery::queryCell("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = {$blogid} AND id = ".$mother):"";
		$permalink	= ($blog['useSlogan'])?"{$defaultURL}/entry/{$slogan}":"{$defaultURL}/".$mother;
		if((!$suri['value'] && count($entries)!=1 && $suri['directive']!="/rss") 
			&& (($data['s1'])?$suri['directive']=="/":"")
			|| (($data['s2'])?$category>0:"") 
			|| (($data['s2'])?$suri['directive']=="/category":"") 
			|| (($data['s3'])?$suri['directive']=="/archive":"") 
			|| (($data['s4'])?$suri['directive']=="/search":"") 
			|| (($data['s5'])?$suri['directive']=="/tag":"") 
			){
			if (($data['s2'])?$suri['directive']=="/category":false) {
				$permalink = ($blog['useSloganOnCategory'])?"{$defaultURL}/entry/{$slogan}":"{$defaultURL}/".$mother;
			} elseif(($data['s5'])?$suri['directive']=="/tag":false) {
				$permalink = ($blog['useSloganOnTag'])?"{$defaultURL}/entry/{$slogan}":"{$defaultURL}/".$mother;
			} else {
				$permalink = ($blog['useSloganOnPost'])?"{$defaultURL}/entry/{$slogan}":"{$defaultURL}/".$mother;
			}
			$contentShort = UTF8::lessenAsEm($content, $data['maxLength']);
			$textstyle = "color:{$data['textcolor']};font-size:{$data['textsize']}px;text-align:right;";
			$target = $contentShort."<br /><br /><div style=\"{$textstyle}\"><strong><a href=\"{$permalink}\"><span style=\"{$textstyle}\">{$data['moretext']}</span></a></strong></div>";
		}
	}
	return $target;
}

function EntryContentShort_DataSet($data){
	global $blog, $service;
	
	requireComponent('Textcube.Function.misc');
	$cfg = misc::fetchConfigVal($data);
	if (!isset($blog['blogLanguage'])) {
		$blog['blogLanguage'] = $service['language'];
	}
	switch($blog['blogLanguage']) {
		case "zh-TW":
			$alertmsg = "::錯 誤::\n\n請選擇一個以上的應用範圍。";
		break;
		case "zh-CN":
			$alertmsg = "::错 误::\n\n请选择一个以上的应用范围。";
		break;
		default:
			$alertmsg = "::선택 오류::\n\n적용 범위는 적어도 하나이상 선택하셔야 합니다.";
	}	

	$checkSuriDirective = array();
	for($i=0; $i <= 5; $i++){
		if($cfg['s'.$i]) 
		array_push($checkSuriDirective, $cfg['s'.$i]);
	}
		 

	if(count($checkSuriDirective)==0) return $alertmsg;
	return true;
}
?>